#@layer()

#define css()
<link rel="stylesheet" href="#(CPATH)/static/components/jquery-file-upload/css/jquery.fileupload.css">
<style>

    .nav-tabs .nav-link {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }

    .attachment_item {
        height: 220px;
        width: 200px;
        padding: 0px;
        border: 1px solid #ddd;
        margin: 10px;
        float: left;
        cursor: pointer;
    }

    .attachment_item:hover {
        border: 1px solid #3c8dbc;
    }

    .attachment_item img {
        height: 90%;
        min-height: 90%;
        width: 100%;
    }

    .attachment_item_title {
        height: 10%;
        background-color: #ecf0f5;
        text-align: center;
        padding: 0 5px;
        overflow: hidden;
    }

    .attachment_item_title p {
        overflow: hidden;
    }

    .my-row {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }

    #uploader {
        height: 230px;
    }

    .myPanel {
        font-size: 25px;
        color: #ccc;
        text-align: center;
        padding-top: 60px;
    }

    .tab-content > .tab-pane {
        padding: 1rem;
    }

    .card.card-outline-tabs .card-header a {
        border-top-color: #dee2e6;
    }


</style>
#end

#define script()
<script src="#(CPATH)/static/components/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script>
<script src="#(CPATH)/static/components/jquery-file-upload/js/jquery.iframe-transport.js"></script>
<script src="#(CPATH)/static/components/jquery-file-upload/js/jquery.fileupload.js"></script>
<script>

    //clear layer.data
    parent.layer.data = {};

    $('#cfile').fileupload({
        dropZone: $('#uploader'),
        url: '#(CPATH)/commons/attachment/upload',
        sequentialUploads: true,
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $(".myPanel").text("上传进度：" + progress + "%")
        },
        done: function (e, data) {
            $(".myPanel").text("或者拖动文件到这里进行上传...");
            if (data.result.state == "ok") {
                parent.layer.data.src = data.result.src;
                parent.layer.data.title = data.result.title;
                parent.layer.closeAll();
            } else {
                showErrorMessage(data.result.message);
            }
        }
    });

    $(".attachment_item").click(function () {
        var src = $(this).children().attr("data-path");
        parent.layer.data.src = src;
        parent.layer.data.title = $(this).children().attr("title");
        parent.layer.closeAll();
    })

</script>
#end

#define content()

<div class="card card-outline card-tabs" style="box-shadow: none;">
    <div class="card-header p-0 border-bottom-0">
        <ul class="nav nav-tabs">
            <li class="nav-item"><a class="nav-link" href="#timeline" data-toggle="tab">上传#para("uititle","图片")</a></li>
            <li class="nav-item"><a class="nav-link active" href="#activity" data-toggle="tab">#para("uititle","图片")库</a></li>
        </ul>

    </div>

    <div class="card-body">
        <div class="tab-content" style="padding-top:20px;">
            <div class="tab-pane" id="timeline">
                <div id="uploader">
                            <span class="btn btn-block btn-primary fileinput-button" style="width: 160px;">
                                <i class="fas fa-plus"></i>
                                <span>选择文件...</span>
                                <input id="cfile" type="file" name="files[]" multiple>
                            </span>

                    <div class="myPanel">
                        或者拖动文件到这里进行上传...
                    </div>

                </div>
            </div>

            <div class="active tab-pane" id="activity">
                <div class="my-row">
                    #for(attachment : page.list)
                    <div class="attachment_item" data-aid="#(attachment.id ??)">
                        #if(attachment.isImage())
                        <img src="#(CPATH)#(attachment.path ??)"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isDoc())
                        <img src="#(CPATH)/static/commons/img/suffix/doc.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isXls())
                        <img src="#(CPATH)/static/commons/img/suffix/xls.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isPpt())
                        <img src="#(CPATH)/static/commons/img/suffix/ppt.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isTxt())
                        <img src="#(CPATH)/static/commons/img/suffix/txt.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isZip())
                        <img src="#(CPATH)/static/commons/img/suffix/zip.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isRar())
                        <img src="#(CPATH)/static/commons/img/suffix/rar.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isExe())
                        <img src="#(CPATH)/static/commons/img/suffix/exe.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isPdf())
                        <img src="#(CPATH)/static/commons/img/suffix/pdf.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isAudio())
                        <img src="#(CPATH)/static/commons/img/suffix/audio.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #elseif(attachment.isVideo())
                        <img src="#(CPATH)/static/commons/img/suffix/video.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #else
                        <img src="#(CPATH)/static/commons/img/suffix/unknow.png"
                             data-path="#(attachment.path ??)"
                             title="#(attachment.title ??)"
                             alt="#(attachment.title ??)">
                        #end
                        <div class="attachment_item_title">
                            <p>#(attachment.title ??)</p>
                        </div>
                    </div>

                    #end
                </div>

                <div class="row" style="padding-right: 20px;padding-top: 30px">
                    <div class="col-12">
                        #@_paginate()
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

#end
